﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xfmMailContent : XtraForm
    {
        private Bar bar1;
        private BarButtonItem barButtonItem1;
        private BarButtonItem barButtonItem10;
        private BarButtonItem barButtonItem11;
        private BarButtonItem barButtonItem12;
        private BarButtonItem barButtonItem13;
        private BarButtonItem barButtonItem14;
        private BarButtonItem barButtonItem15;
        private BarButtonItem barButtonItem16;
        private BarButtonItem barButtonItem17;
        private BarButtonItem barButtonItem18;
        private BarButtonItem barButtonItem2;
        private BarButtonItem barButtonItem3;
        private BarButtonItem barButtonItem4;
        private BarButtonItem barButtonItem5;
        private BarButtonItem barButtonItem6;
        private BarButtonItem barButtonItem7;
        private BarButtonItem barButtonItem8;
        private BarButtonItem barButtonItem9;
        private BarDockControl barDockControlBottom;
        private BarDockControl barDockControlLeft;
        private BarDockControl barDockControlRight;
        private BarDockControl barDockControlTop;
        private BarManager barManager1;
        private BarButtonItem bbiN;
        private SimpleButton bbiSend;
        private SimpleButton bbiSendSave;
        private CheckEdit cheAttach;
        private CheckEdit cheShowSendMail;
        private IContainer components;
        private DevExpress.Utils.ImageCollection imageCollection1;
        private int m_Type;
        private MemoEdit mmContent;

        public event SendHander Sended;

        public xfmMailContent()
        {
            this.components = null;
            this.m_Type = 1;
            this.InitializeComponent();
        }

        public xfmMailContent(int Type)
        {
            this.components = null;
            this.m_Type = 1;
            this.InitializeComponent();
            this.m_Type = Type;
            this.Init();
        }

        private void bbiContent_ItemClick(object sender, ItemClickEventArgs e)
        {
            int selectionStart = this.mmContent.SelectionStart;
            this.mmContent.Text = this.mmContent.Text.Insert(this.mmContent.SelectionStart, e.Item.Caption);
            this.mmContent.SelectionStart = selectionStart + e.Item.Caption.Length;
        }

        private void bbiSend_Click(object sender, EventArgs e)
        {
            this.RaiseSendHander(this.mmContent.Text, this.cheAttach.Checked);
        }

        private void bbiSendSave_Click(object sender, EventArgs e)
        {
            if (this.m_Type == 1)
            {
                this.SaveTimekeeperMailContent(this.mmContent.Text);
            }
            else if (this.m_Type == 2)
            {
                this.SaveSalaryMailContent(this.mmContent.Text);
            }
            this.RaiseSendHander(this.mmContent.Text, this.cheAttach.Checked);
        }

        private void cheShowSendMail_CheckedChanged(object sender, EventArgs e)
        {
            new clsAllOption { ShowSendMail = this.cheShowSendMail.Checked }.SaveOption();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Init()
        {
            if (this.m_Type == 1)
            {
                this.cheAttach.Text = "Đ\x00ednh k\x00e8m bảng chấm c\x00f4ng v\x00e0o ra khi gửi mail";
                this.mmContent.Text = this.LoadTimekeeperMailContent();
            }
            else if (this.m_Type == 2)
            {
                this.cheAttach.Text = "Đ\x00ednh k\x00e8m phiếu t\x00ednh lương khi gửi mail";
                this.mmContent.Text = this.LoadSalaryMailContent();
            }
        }

        public void Init(int Type)
        {
            this.m_Type = Type;
            if (this.m_Type == 1)
            {
                this.cheAttach.Text = "Đ\x00ednh k\x00e8m bảng chấm c\x00f4ng v\x00e0o ra khi gửi mail";
                this.mmContent.Text = this.LoadTimekeeperMailContent();
            }
            else if (this.m_Type == 2)
            {
                this.cheAttach.Text = "Đ\x00ednh k\x00e8m phiếu t\x00ednh lương khi gửi mail";
                this.mmContent.Text = this.LoadSalaryMailContent();
            }
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmMailContent));
            this.imageCollection1 = new DevExpress.Utils.ImageCollection(this.components);
            this.barManager1 = new BarManager(this.components);
            this.bar1 = new Bar();
            this.barButtonItem1 = new BarButtonItem();
            this.barButtonItem2 = new BarButtonItem();
            this.barButtonItem3 = new BarButtonItem();
            this.barButtonItem4 = new BarButtonItem();
            this.barButtonItem5 = new BarButtonItem();
            this.barButtonItem10 = new BarButtonItem();
            this.barButtonItem6 = new BarButtonItem();
            this.barButtonItem9 = new BarButtonItem();
            this.barButtonItem11 = new BarButtonItem();
            this.barButtonItem18 = new BarButtonItem();
            this.barButtonItem17 = new BarButtonItem();
            this.barButtonItem12 = new BarButtonItem();
            this.barButtonItem13 = new BarButtonItem();
            this.barButtonItem14 = new BarButtonItem();
            this.barButtonItem15 = new BarButtonItem();
            this.barButtonItem16 = new BarButtonItem();
            this.barButtonItem7 = new BarButtonItem();
            this.barButtonItem8 = new BarButtonItem();
            this.bbiN = new BarButtonItem();
            this.barDockControlTop = new BarDockControl();
            this.barDockControlBottom = new BarDockControl();
            this.barDockControlLeft = new BarDockControl();
            this.barDockControlRight = new BarDockControl();
            this.cheAttach = new CheckEdit();
            this.mmContent = new MemoEdit();
            this.bbiSend = new SimpleButton();
            this.bbiSendSave = new SimpleButton();
            this.cheShowSendMail = new CheckEdit();
            this.imageCollection1.BeginInit();
            this.barManager1.BeginInit();
            this.cheAttach.Properties.BeginInit();
            this.mmContent.Properties.BeginInit();
            this.cheShowSendMail.Properties.BeginInit();
            base.SuspendLayout();
            this.imageCollection1.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection1.ImageStream");
            this.imageCollection1.Images.SetKeyName(0, "direction_next.png");
            this.imageCollection1.Images.SetKeyName(1, "document_small_upload.png");
            this.barManager1.Bars.AddRange(new Bar[] { this.bar1 });
            this.barManager1.DockControls.Add(this.barDockControlTop);
            this.barManager1.DockControls.Add(this.barDockControlBottom);
            this.barManager1.DockControls.Add(this.barDockControlLeft);
            this.barManager1.DockControls.Add(this.barDockControlRight);
            this.barManager1.Form = this;
            this.barManager1.Images = this.imageCollection1;
            this.barManager1.Items.AddRange(new BarItem[] { 
                this.barButtonItem1, this.barButtonItem2, this.barButtonItem3, this.barButtonItem4, this.barButtonItem5, this.barButtonItem6, this.barButtonItem7, this.barButtonItem8, this.bbiN, this.barButtonItem9, this.barButtonItem10, this.barButtonItem11, this.barButtonItem12, this.barButtonItem13, this.barButtonItem14, this.barButtonItem15, 
                this.barButtonItem16, this.barButtonItem17, this.barButtonItem18
             });
            this.barManager1.MaxItemId = 0x16;
            this.bar1.BarName = "Tools";
            this.bar1.DockCol = 0;
            this.bar1.DockRow = 0;
            this.bar1.DockStyle = BarDockStyle.Top;
            this.bar1.LinksPersistInfo.AddRange(new LinkPersistInfo[] { 
                new LinkPersistInfo(this.barButtonItem1), new LinkPersistInfo(this.barButtonItem2), new LinkPersistInfo(this.barButtonItem3), new LinkPersistInfo(this.barButtonItem4), new LinkPersistInfo(this.barButtonItem5), new LinkPersistInfo(this.barButtonItem10), new LinkPersistInfo(this.barButtonItem6), new LinkPersistInfo(this.barButtonItem9), new LinkPersistInfo(this.barButtonItem11), new LinkPersistInfo(this.barButtonItem18), new LinkPersistInfo(this.barButtonItem17), new LinkPersistInfo(this.barButtonItem12, true), new LinkPersistInfo(this.barButtonItem13, true), new LinkPersistInfo(this.barButtonItem14), new LinkPersistInfo(this.barButtonItem15), new LinkPersistInfo(this.barButtonItem16, true), 
                new LinkPersistInfo(this.barButtonItem7, true), new LinkPersistInfo(this.barButtonItem8), new LinkPersistInfo(this.bbiN, true)
             });
            this.bar1.OptionsBar.AllowQuickCustomization = false;
            this.bar1.OptionsBar.DrawDragBorder = false;
            this.bar1.OptionsBar.MultiLine = true;
            this.bar1.OptionsBar.UseWholeRow = true;
            this.bar1.Text = "Tools";
            this.barButtonItem1.Caption = "[M\x00e3 nh\x00e2n vi\x00ean]";
            this.barButtonItem1.Id = 3;
            this.barButtonItem1.Name = "barButtonItem1";
            this.barButtonItem1.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem2.Appearance.ForeColor = Color.Green;
            this.barButtonItem2.Appearance.Options.UseForeColor = true;
            this.barButtonItem2.Caption = "[Họ l\x00f3t]";
            this.barButtonItem2.Id = 4;
            this.barButtonItem2.Name = "barButtonItem2";
            this.barButtonItem2.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem3.Appearance.ForeColor = Color.Green;
            this.barButtonItem3.Appearance.Options.UseForeColor = true;
            this.barButtonItem3.Caption = "[T\x00ean]";
            this.barButtonItem3.Id = 5;
            this.barButtonItem3.Name = "barButtonItem3";
            this.barButtonItem3.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem4.Caption = "[Ng\x00e0y sinh]";
            this.barButtonItem4.Id = 6;
            this.barButtonItem4.Name = "barButtonItem4";
            this.barButtonItem4.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem5.Caption = "[Giới t\x00ednh]";
            this.barButtonItem5.Id = 7;
            this.barButtonItem5.Name = "barButtonItem5";
            this.barButtonItem5.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem10.Caption = "[Nơi sinh]";
            this.barButtonItem10.Id = 13;
            this.barButtonItem10.Name = "barButtonItem10";
            this.barButtonItem10.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem6.Caption = "[Địa chỉ]";
            this.barButtonItem6.Id = 8;
            this.barButtonItem6.Name = "barButtonItem6";
            this.barButtonItem6.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem9.Caption = "[Tạm tr\x00fa]";
            this.barButtonItem9.Id = 12;
            this.barButtonItem9.Name = "barButtonItem9";
            this.barButtonItem9.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem11.Caption = "[CMND]";
            this.barButtonItem11.Id = 14;
            this.barButtonItem11.Name = "barButtonItem11";
            this.barButtonItem11.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem18.Caption = "[Email]";
            this.barButtonItem18.Id = 0x15;
            this.barButtonItem18.Name = "barButtonItem18";
            this.barButtonItem18.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem17.Caption = "[Điện thoại]";
            this.barButtonItem17.Id = 20;
            this.barButtonItem17.Name = "barButtonItem17";
            this.barButtonItem17.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem12.Caption = "[Chức vụ]";
            this.barButtonItem12.Id = 15;
            this.barButtonItem12.Name = "barButtonItem12";
            this.barButtonItem12.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem13.Appearance.ForeColor = Color.Teal;
            this.barButtonItem13.Appearance.Options.UseForeColor = true;
            this.barButtonItem13.Caption = "[Chi nh\x00e1nh]";
            this.barButtonItem13.Id = 0x10;
            this.barButtonItem13.Name = "barButtonItem13";
            this.barButtonItem13.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem14.Appearance.ForeColor = Color.Teal;
            this.barButtonItem14.Appearance.Options.UseForeColor = true;
            this.barButtonItem14.Caption = "[Ph\x00f2ng ban]";
            this.barButtonItem14.Id = 0x11;
            this.barButtonItem14.Name = "barButtonItem14";
            this.barButtonItem14.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem15.Appearance.ForeColor = Color.Teal;
            this.barButtonItem15.Appearance.Options.UseForeColor = true;
            this.barButtonItem15.Caption = "[Tổ nh\x00f3m]";
            this.barButtonItem15.Id = 0x12;
            this.barButtonItem15.Name = "barButtonItem15";
            this.barButtonItem15.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem16.Caption = "[Lương căn bản]";
            this.barButtonItem16.Id = 0x13;
            this.barButtonItem16.Name = "barButtonItem16";
            this.barButtonItem16.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem7.Appearance.ForeColor = Color.Red;
            this.barButtonItem7.Appearance.Options.UseForeColor = true;
            this.barButtonItem7.Caption = "[Th\x00e1ng]";
            this.barButtonItem7.Id = 9;
            this.barButtonItem7.Name = "barButtonItem7";
            this.barButtonItem7.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.barButtonItem8.Appearance.ForeColor = Color.Red;
            this.barButtonItem8.Appearance.Options.UseForeColor = true;
            this.barButtonItem8.Caption = "[Năm]";
            this.barButtonItem8.Id = 10;
            this.barButtonItem8.Name = "barButtonItem8";
            this.barButtonItem8.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.bbiN.Appearance.ForeColor = Color.Blue;
            this.bbiN.Appearance.Options.UseForeColor = true;
            this.bbiN.Caption = "[Xuống d\x00f2ng]";
            this.bbiN.Id = 11;
            this.bbiN.Name = "bbiN";
            this.bbiN.ItemClick += new ItemClickEventHandler(this.bbiContent_ItemClick);
            this.cheAttach.EditValue = true;
            this.cheAttach.Location = new Point(13, 0x42);
            this.cheAttach.MenuManager = this.barManager1;
            this.cheAttach.Name = "cheAttach";
            this.cheAttach.Properties.Caption = "Đ\x00ednh k\x00e8m tập tin khi gửi mail";
            this.cheAttach.Size = new Size(0x185, 0x13);
            this.cheAttach.TabIndex = 4;
            this.mmContent.EditValue = "";
            this.mmContent.Location = new Point(15, 0x5b);
            this.mmContent.MenuManager = this.barManager1;
            this.mmContent.Name = "mmContent";
            this.mmContent.Size = new Size(0x263, 0x102);
            this.mmContent.TabIndex = 5;
            this.bbiSend.ImageIndex = 0;
            this.bbiSend.ImageList = this.imageCollection1;
            this.bbiSend.Location = new Point(0x1ac, 0x16b);
            this.bbiSend.Name = "bbiSend";
            this.bbiSend.Size = new Size(0x54, 0x17);
            this.bbiSend.TabIndex = 6;
            this.bbiSend.Text = "Gửi Đi";
            this.bbiSend.Click += new EventHandler(this.bbiSend_Click);
            this.bbiSendSave.ImageIndex = 1;
            this.bbiSendSave.ImageList = this.imageCollection1;
            this.bbiSendSave.Location = new Point(0x206, 0x16b);
            this.bbiSendSave.Name = "bbiSendSave";
            this.bbiSendSave.Size = new Size(0x6c, 0x17);
            this.bbiSendSave.TabIndex = 7;
            this.bbiSendSave.Text = "Lưu Lại && Gửi";
            this.bbiSendSave.Click += new EventHandler(this.bbiSendSave_Click);
            this.cheShowSendMail.EditValue = true;
            this.cheShowSendMail.Location = new Point(12, 0x169);
            this.cheShowSendMail.MenuManager = this.barManager1;
            this.cheShowSendMail.Name = "cheShowSendMail";
            this.cheShowSendMail.Properties.Caption = "Hiển thị hộp thoại n\x00e0y khi gửi mail";
            this.cheShowSendMail.Size = new Size(0xeb, 0x13);
            this.cheShowSendMail.TabIndex = 8;
            this.cheShowSendMail.CheckedChanged += new EventHandler(this.cheShowSendMail_CheckedChanged);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x27e, 0x18d);
            base.Controls.Add(this.cheShowSendMail);
            base.Controls.Add(this.bbiSendSave);
            base.Controls.Add(this.bbiSend);
            base.Controls.Add(this.mmContent);
            base.Controls.Add(this.cheAttach);
            base.Controls.Add(this.barDockControlLeft);
            base.Controls.Add(this.barDockControlRight);
            base.Controls.Add(this.barDockControlBottom);
            base.Controls.Add(this.barDockControlTop);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmMailContent";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "Nội Dung Gửi Mail";
            this.imageCollection1.EndInit();
            this.barManager1.EndInit();
            this.cheAttach.Properties.EndInit();
            this.mmContent.Properties.EndInit();
            this.cheShowSendMail.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private string LoadSalaryMailContent()
        {
            try
            {
                DataSet set = new DataSet();
                set.ReadXml(Application.StartupPath + @"\Layout\sendMailSalary.xml");
                return set.Tables[0].Rows[0][0].ToString();
            }
            catch
            {
                return "Ch\x00e0o [Giới t\x00ednh] [Họ l\x00f3t] [T\x00ean] th\x00e2n mến![Xuống d\x00f2ng]Hiện tại phiếu t\x00ednh lương th\x00e1ng [Th\x00e1ng]/[Năm] đ\x00e3 c\x00f3. [Giới t\x00ednh] c\x00f3 thể download file k\x00e8m theo dưới đ\x00e2y để tham khảo. Nếu c\x00f3 g\x00ec thắc mắc cần được giải đ\x00e1p, [Giới t\x00ednh] c\x00f3 thể phản hồi trở lại bằng địa chỉ email n\x00e0y.[Xuống d\x00f2ng]Th\x00e2n ch\x00e0o! Ch\x00fac vui vẻ!";
            }
        }

        private string LoadTimekeeperMailContent()
        {
            try
            {
                DataSet set = new DataSet();
                set.ReadXml(Application.StartupPath + @"\Layout\sendMailTimekeeping.xml");
                return set.Tables[0].Rows[0][0].ToString();
            }
            catch
            {
                return "Ch\x00e0o [Giới t\x00ednh] [Họ l\x00f3t] [T\x00ean] th\x00e2n mến![Xuống d\x00f2ng]Hiện tại bảng chấm c\x00f4ng v\x00e0o ra th\x00e1ng [Th\x00e1ng]/[Năm] đ\x00e3 c\x00f3. [Giới t\x00ednh] c\x00f3 thể download file k\x00e8m theo dưới đ\x00e2y để tham khảo. Nếu c\x00f3 g\x00ec thắc mắc cần được giải đ\x00e1p, [Giới t\x00ednh] c\x00f3 thể phản hồi trở lại bằng địa chỉ email n\x00e0y.[Xuống d\x00f2ng]Th\x00e2n ch\x00e0o! Ch\x00fac vui vẻ!";
            }
        }

        private void RaiseSendHander(string Content, bool Attach)
        {
            if (this.Sended != null)
            {
                this.Sended(this, Content, Attach);
            }
        }

        private void SaveSalaryMailContent(string Content)
        {
            DataSet set = new DataSet();
            using (DataTable table = new DataTable())
            {
                table.Columns.Add("Content", typeof(string));
                object[] objArray = new object[] { Content.ToString() };
                table.Rows.Add(new object[0]);
                table.Rows[0][0] = objArray[0];
                set.Tables.Add(table);
            }
            try
            {
                set.WriteXml(Application.StartupPath + @"\Layout\sendMailSalary.xml");
            }
            catch
            {
            }
        }

        private void SaveTimekeeperMailContent(string Content)
        {
            DataSet set = new DataSet();
            using (DataTable table = new DataTable())
            {
                table.Columns.Add("Content", typeof(string));
                object[] objArray = new object[] { Content.ToString() };
                table.Rows.Add(new object[0]);
                table.Rows[0][0] = objArray[0];
                set.Tables.Add(table);
            }
            try
            {
                set.WriteXml(Application.StartupPath + @"\Layout\sendMailTimekeeping.xml");
            }
            catch
            {
            }
        }

        public delegate void SendHander(object sender, string Content, bool Attach);
    }
}

